import { createApp, h } from 'vue'
import './style.css'
import App from './App.vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import router from './router'
import 'element-plus/dist/index.css'
import { createPinia } from 'pinia'
import VueScrollTo from 'vue-scrollto'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import Pagination from './components/Pagination.vue'

// 创建应用实例但不立即挂载
const app = createApp({
  render: () => h(App),
  mounted() {
    (function(z, h, i, m, a, j, s) { 
      z[m] = z[m] || function() {
        (z[m].a = z[m].a || []).push(arguments)
      };
      j = h.createElement(i),
      s = h.getElementsByTagName(i)[0];
      j.async = true;
      j.charset = 'UTF-8';
      j.setAttribute("data-json", JSON.stringify({ 
        id:12164,
        token:'a8d35983fea0f5ebf5b21f293ad2454f',
        customer: 0, // 控制是否显示客服图标，0为显示，1为不显示
        language: 'ZH' // 控制显示语言，ZH为中文，EN为英文
      }));
      j.id = "xiaokefu_js";
      j.src = 'https://pcjs.xiaokefu.com.cn/static/pc_Access/dist/pcAccess.js?version=' + parseInt(new Date().getTime() / 3600000);
      s.parentNode.insertBefore(j, s);
    })(window, document, 'script', '_xiaokefu');
  }
})

// 注册所有Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

const pinia = createPinia()

// 安装插件和组件
app.use(ElementPlus, {
  locale: zhCn,
})
app.use(router)
app.use(pinia)
app.use(VueScrollTo)
app.component('Pagination', Pagination)

// 最后挂载应用
app.mount('#app')